package com.mtl.inmigrant.shoes;


import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.mtl.inmigrant.shoes.adapter.ImmigrantListAdapter;
import com.mtl.inmigrant.shoes.entity.ShoeActionsInmigrant;
import com.mtl.inmigrant.shoes.sqlite.ShoesDataSource;

public class ActivitiesImmigrantListActivity extends ListActivity  {
	
	private ShoesDataSource dataSource;
	ImmigrantListAdapter adapter;

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        dataSource = new ShoesDataSource(this);
		dataSource.open();
		
		List<ShoeActionsInmigrant> values = dataSource.getAllShoesActions();
        
		adapter = new ImmigrantListAdapter(this, values, dataSource);
		setListAdapter(adapter);
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		ShoeActionsInmigrant element = adapter.getItem(position); 
		
		/*dataSource.open();
		element = dataSource.getOneShoeAction(element.getIdActivity(), typeActionShoe.TASK.toString());
		dataSource.close();		*/

		if (element != null){
			Bundle bundle = new Bundle();
			bundle.putString("idActivity", element.getIdActivity());
			Intent i = new Intent(ActivitiesImmigrantListActivity.this, TaskImmigrantListActivity.class);
			i.putExtras(bundle);
			startActivity(i);
		}
		else
			Toast.makeText(getApplicationContext(), " No tasks created!!!" , Toast.LENGTH_LONG).show();
		
		/*
		if (element == null)
			Toast.makeText(getApplicationContext(), " No tasks created!!!" , Toast.LENGTH_LONG).show();
		else
			Toast.makeText(getApplicationContext(), "Click ListItem Number " + element.toString(), Toast.LENGTH_LONG).show();
		Toast.makeText(getApplicationContext(),"Click ListItem Number " + position, Toast.LENGTH_LONG).show();
		*/
	}
	
	 @Override
	 protected void onDestroy() {
	  // TODO Auto-generated method stub
	  super.onDestroy();
	  dataSource.close();
	 }
}
